<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!-- 新增/Add -->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="../../layui/css/layui.css">
    <link rel="stylesheet" href="../../css/diy.css">
    <script src="../../js/axios.min.js"></script>

    <style>
        img {
            width: 200px;
        }


    </style>
</head>

<body>
<article class="sign_in">
    <div class="warp tpl">
        <div class="layui-container">
            <div class="layui-row">
                <form class="layui-form" action="">
                    <div class="from-input-box-i">
                        <div class="layui-form-item uid-box" id="booking_account_box">
                            <label class="layui-form-label">预订账号</label>
                            <div class="layui-input-block select block">
                                <select name="interest" lay-filter="booking_account"
                                        id="booking_account">
                                    <option value=""></option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item unique" id="booking_number_box">
                            <label class="layui-form-label">预订编号</label>
                            <div class="layui-input-block input-i block">
                                <input type="text" name="title" lay-verify="title" autocomplete="off"
                                       placeholder="请输入预订编号"
                                       class="layui-input" id="booking_number">
                            </div>
                        </div>
                        <div class="layui-form-item unique" id="user_name_box">
                            <label class="layui-form-label">用户姓名</label>
                            <div class="layui-input-block input-i block">
                                <input type="text" name="title" lay-verify="title" autocomplete="off"
                                       placeholder="请输入用户姓名"
                                       class="layui-input" id="user_name">
                            </div>
                        </div>
                        <div class="layui-form-item unique" id="identity_documents_box">
                            <label class="layui-form-label">身份证件</label>
                            <div class="layui-input-block input-i block">
                                <input type="text" name="title" lay-verify="title" autocomplete="off"
                                       placeholder="请输入身份证件"
                                       class="layui-input" id="identity_documents">
                            </div>
                        </div>
                        <div class="layui-form-item unique" id="user_gender_box">
                            <label class="layui-form-label">用户性别</label>
                            <div class="layui-input-block input-i block">
                                <input type="text" name="title" lay-verify="title" autocomplete="off"
                                       placeholder="请输入用户性别"
                                       class="layui-input" id="user_gender">
                            </div>
                        </div>
                        <div class="layui-form-item unique" id="user_phone_number_box">
                            <label class="layui-form-label">用户电话</label>
                            <div class="layui-input-block input-i block">
                                <input type="text" name="title" lay-verify="title" autocomplete="off"
                                       placeholder="请输入用户电话"
                                       class="layui-input" id="user_phone_number">
                            </div>
                        </div>
                        <div class="layui-form-item unique" id="route_name_box">
                            <label class="layui-form-label">路线名称</label>
                            <div class="layui-input-block input-i block">
                                <input type="text" name="title" lay-verify="title" autocomplete="off"
                                       placeholder="请输入路线名称"
                                       class="layui-input" id="route_name">
                            </div>
                        </div>
                        <div class="layui-form-item unique" id="route_number_box">
                            <label class="layui-form-label">路线编号</label>
                            <div class="layui-input-block input-i block">
                                <input type="text" name="title" lay-verify="title" autocomplete="off"
                                       placeholder="请输入路线编号"
                                       class="layui-input" id="route_number">
                            </div>
                        </div>
                        <div class="layui-form-item unique" id="individual_expenses_box">
                            <label class="layui-form-label">单人费用</label>
                            <div class="layui-input-block input-i block">
                                <input type="text" name="title" lay-verify="title" autocomplete="off"
                                       placeholder="请输入单人费用"
                                       class="layui-input" id="individual_expenses">
                            </div>
                        </div>
                        <div class="layui-form-item number" id="number_of_bookings_box">
                            <label class="layui-form-label">预订人数</label>
                            <div class="layui-input-block input-i block">
                                <input type="number" name="num" class="layui-input num" id="number_of_bookings">
                            </div>
                        </div>
                        <div class="layui-form-item compute" id="total_amount_box">
                            <label class="layui-form-label">总计金额</label>
                            <div class="layui-input-block input-i block">
                                <input type="text" name="title" lay-verify="title" autocomplete="off"
                                       placeholder="请输入总计金额"
                                       class="layui-input" id="total_amount">
                            </div>
                        </div>
                        <div class="layui-form-item unique" id="booking_time_box">
                            <label class="layui-form-label">预订时间</label>
                            <div class="layui-input-block input-i block">
                                <input type="text" name="title" lay-verify="title" autocomplete="off"
                                       placeholder="请选择预订时间"
                                       class="layui-input" id="booking_time">
                            </div>
                        </div>
                        <div class="layui-form-item layui-form-text" id="booking_remarks_box">
                            <label class="layui-form-label">预订备注</label>
                            <div class="layui-input-block text">
                                            <textarea placeholder="请输入预订备注" class="layui-textarea"
                                                      id="booking_remarks"></textarea>
                            </div>
                        </div>
                        <div class="layui-form-item examine">
                            <label class="layui-form-label">审核状态</label>
                            <div class="layui-input-block select block">
                                <select name="interest" lay-filter="examine_state" id="examine_state">
                                    <option value=""></option>
                                    <option value="0">未审核</option>
                                    <option value="1">已通过</option>
                                    <option value="2">未通过</option>
                                </select>
                            </div>
                        </div>

                        <div class="layui-form-item examine">
                            <label class="layui-form-label">审核回复</label>
                            <div class="layui-input-block input-i block">
                                <input type="text" name="title" lay-verify="title" autocomplete="off"
                                       placeholder="请输入审核回复"
                                       class="layui-input" id="examine_reply">
                            </div>
                        </div>


                    </div>
                </form>
                <div class="layui-btn-container">
                    <button type="button" class="layui-btn layui-btn-normal login" id="submit">确认</button>
                    <button type="button" class="layui-btn layui-btn-normal login" id="cancel">取消</button>
                </div>
            </div>
        </div>
    </div>
</article>
</body>
<script src="../../layui/layui.js"></script>
<script src="../../js/base.js"></script>
<script src="../../js/index.js"></script>

<script>
    var BaseUrl = baseUrl()
    let cancel = document.querySelector("#cancel")
    cancel.addEventListener("click", () => {
        colseLayer()
    })
    let booking_records_id = location.search.substring(1)
    layui.use(['upload', 'element', 'layer', 'laydate', 'layedit'], function () {
        var $ = layui.jquery
            , upload = layui.upload
            , element = layui.element
            , layer = layui.layer
            , laydate = layui.laydate
            , layedit = layui.layedit
            , form = layui.form;

        let url

        let token = sessionStorage.token || null
        let personInfo = JSON.parse(sessionStorage.personInfo)
        let user_group = personInfo.user_group
        let use_id = personInfo.user_id


        function $get_stamp() {
            return new Date().getTime();
        }

        function $get_rand(len) {
            var rand = Math.random();
            return Math.ceil(rand * 10 ** len);
        }


        // 权限判断
        /**
         * 获取路径对应操作权限 鉴权
         * @param {String} action 操作名
         */
        function $check_action(path1, action = "get") {
            var o = $get_power(path1);
            if (o && o[action] != 0 && o[action] != false) {
                return true;
            }
            return false;
        }

        /**
         * 是否有显示或操作字段的权限
         * @param {String} action 操作名
         * @param {String} field 查询的字段
         */
        function $check_field(action, field, path1) {
            var o = $get_power(path1);
            var auth;
            if (o && o[action] != 0 && o[action] != false) {
                auth = o["field_" + action];
            }
            if (auth) {
                return auth.indexOf(field) !== -1;
            }
            return false;
        }

        /**
         * 获取权限
         * @param {String} path 路由路径
         */
        function $get_power(path) {
            var list_data = JSON.parse(sessionStorage.list_data)
            var list = list_data;
            var obj;
            for (var i = 0; i < list.length; i++) {
                var o = list[i];
                if (o.path === path) {
                    obj = o;
                    break;
                }
            }
            return obj;
        }

        let submit = document.querySelector('#submit')
        // 提交按钮校验权限
        if (user_group == "管理员" || $check_action('/booking_records/view', 'add') || $check_action('/booking_records/view', 'set') || $check_option('/booking_records/table', 'examine')) {
        } else {
            $("#submit").hide()
        }
        // style="display: none"


        let field = "booking_records_id";
        let url_add = "booking_records";
        let url_set = "booking_records";
        let url_get_obj = "booking_records";
        let url_upload = "booking_records"
        let query = {
            "booking_records_id": 0,
        }

        let form_data2 = {
            "booking_account": 0, // 预订账号
            "booking_number": $get_stamp(), // 预订编号
            "user_name": '', // 用户姓名
            "identity_documents": '', // 身份证件
            "user_gender": '', // 用户性别
            "user_phone_number": '', // 用户电话
            "route_name": '', // 路线名称
            "route_number": '', // 路线编号
            "individual_expenses": '', // 单人费用
            "number_of_bookings": 0, // 预订人数
            "total_amount": '', // 总计金额
            "booking_time": '', // 预订时间
            "booking_remarks": '', // 预订备注
            "examine_state": "未审核",
            "examine_reply": "",
            "booking_records_id": 0, // ID
        }

        layui.layedit.set({
            uploadImage: {
                url: BaseUrl + '/api/booking_records/upload?' //接口url
                , type: 'post' //默认post
            }
        });


        var path1

        function getpath() {
            var list_data = JSON.parse(sessionStorage.list_data)
            for (var i = 0; i < list_data.length; i++) {
                var o = list_data[i];
                if (o.path === "/booking_records/table") {
                    path1 = o.path
                    $get_power(o.path)
                }
            }
        }

        getpath()

        /**
         * 注册时是否有显示或操作字段的权限
         * @param {String} action 操作名
         * @param {String} field 查询的字段
         * @param {String} path 路径
         */
        function $check_register_field(action, field, path1) {
            var o = $get_power(path1);
            var auth;
            if (o && o[action] != 0 && o[action] != false) {
                auth = o["field_" + action];
            }
            if (auth) {
                return auth.indexOf(field) !== -1;
            }
            return false;
        }

        /**
         * 是否有显示或操作字段的权限
         * @param {String} action 操作名
         * @param {String} field 查询的字段
         */
        function $check_field(action, field) {
            var o = $get_power("/booking_records/view");
            var auth;
            if (o && o[action] != 0 && o[action] != false) {
                auth = o["field_" + action];
            }
            if (auth) {
                return auth.indexOf(field) !== -1;
            }
            return false;
        }

        /**
         * 获取路径对应操作权限 鉴权
         * @param {String} action 操作名
         */
        function $check_exam(path1, action = "get") {
            var o = $get_power(path1);
            if (o) {
                var option = JSON.parse(o.option);
                if (option[action])
                    return true
            }
            return false;
        }

        function $check_option(path, op) {
            var o = $get_power(path);
            if (o) {
                var option = JSON.parse(o.option);
                if (option[op])
                    return true
            }
            return false;
        }

        /**
         * 是否有审核字段的权限
         */
        function $check_examine() {
            var url = window.location.href;
            var url_ = url.split("/")
            var pg_url = url_[url_.length - 2]
            let path = "/" + pg_url + "/table"
            var o = $get_power(path);
            if (o) {
                var option = JSON.parse(o.option);
                if (option.examine)
                    return true
            }
            return false;
        }

        if (user_group === '管理员') {
            $("#booking_account_box").show()
        } else {
            if ($check_field('add', 'booking_account')) {
                $("#booking_account_box").show()
            } else {
                $("#booking_account_box").hide()
            }
        }
        if (user_group === '管理员') {
            $("#booking_number_box").show()
        } else {
            if ($check_field('add', 'booking_number')) {
                $("#booking_number_box").show()
            } else {
                $("#booking_number_box").hide()
            }
        }
        if (user_group === '管理员') {
            $("#user_name_box").show()
        } else {
            if ($check_field('add', 'user_name')) {
                $("#user_name_box").show()
            } else {
                $("#user_name_box").hide()
            }
        }
        if (user_group === '管理员') {
            $("#identity_documents_box").show()
        } else {
            if ($check_field('add', 'identity_documents')) {
                $("#identity_documents_box").show()
            } else {
                $("#identity_documents_box").hide()
            }
        }
        if (user_group === '管理员') {
            $("#user_gender_box").show()
        } else {
            if ($check_field('add', 'user_gender')) {
                $("#user_gender_box").show()
            } else {
                $("#user_gender_box").hide()
            }
        }
        if (user_group === '管理员') {
            $("#user_phone_number_box").show()
        } else {
            if ($check_field('add', 'user_phone_number')) {
                $("#user_phone_number_box").show()
            } else {
                $("#user_phone_number_box").hide()
            }
        }
        if (user_group === '管理员') {
            $("#route_name_box").show()
        } else {
            if ($check_field('add', 'route_name')) {
                $("#route_name_box").show()
            } else {
                $("#route_name_box").hide()
            }
        }
        if (user_group === '管理员') {
            $("#route_number_box").show()
        } else {
            if ($check_field('add', 'route_number')) {
                $("#route_number_box").show()
            } else {
                $("#route_number_box").hide()
            }
        }
        if (user_group === '管理员') {
            $("#individual_expenses_box").show()
        } else {
            if ($check_field('add', 'individual_expenses')) {
                $("#individual_expenses_box").show()
            } else {
                $("#individual_expenses_box").hide()
            }
        }
        if (user_group === '管理员') {
            $("#number_of_bookings_box").show()
        } else {
            if ($check_field('add', 'number_of_bookings')) {
                $("#number_of_bookings_box").show()
            } else {
                $("#number_of_bookings_box").hide()
            }
        }
        if (user_group === '管理员') {
            $("#total_amount_box").show()
        } else {
            if ($check_field('add', 'total_amount')) {
                $("#total_amount_box").show()
            } else {
                $("#total_amount_box").hide()
            }
        }
        if (user_group === '管理员') {
            $("#booking_time_box").show()
        } else {
            if ($check_field('add', 'booking_time')) {
                $("#booking_time_box").show()
            } else {
                $("#booking_time_box").hide()
            }
        }
        if (user_group === '管理员') {
            $("#booking_remarks_box").show()
        } else {
            if ($check_field('add', 'booking_remarks')) {
                $("#booking_remarks_box").show()
            } else {
                $("#booking_remarks_box").hide()
            }
        }


        laydate.render({
            elem: '#booking_time'
            , type: 'datetime'
            , done: function (value) {
                console.log(value)
                form_data2.booking_time = value
            }
        });


        async function list_booking_account() {
            var booking_account = document.querySelector("#booking_account")
            var op1 = document.createElement("option");
            op1.value = '0'
            booking_account.appendChild(op1)
            // 收集数据 长度
            var count
            // 收集数据 数组
            var arr = []
            $.ajax({
                url: BaseUrl + '/api/user/get_list?user_group=注册用户',
                type: 'GET',
                contentType: 'application/json; charset=UTF-8',
                async: false,
                dataType: 'json',
                success: function (response) {
                    count = response.result.count
                    arr = response.result.list
                }
            })
            for (var i = 0; i < arr.length; i++) {
                var op = document.createElement("option");
                // 给节点赋值
                op.innerHTML = arr[i].username + "--" + arr[i].nickname
                op.value = arr[i].user_id
                // 新增/Add节点
                booking_account.appendChild(op)
                if (form_data2.booking_account == arr[i].booking_account) {
                    op.selected = true
                }
                layui.form.render("select");
            }
        }

        layui.form.on('select(booking_account)', function (data) {
            form_data2.booking_account = Number(data.elem[data.elem.selectedIndex].value);
        })
        list_booking_account()


        layui.form.on('select(examine_state)', function (data) {
            form_data2.examine_state = data.elem[data.elem.selectedIndex].text;
        })
        if (user_group === '管理员' || (form_data2['examine_state'] && $check_examine()) || (!form_data2['examine_state'] && $check_examine())) {
            console.log(111)
        } else {
            $("#examine_state").attr("disabled", "disabled");
        }
        if (user_group === '管理员' || (form_data2['examine_reply'] && $check_examine()) || (!form_data2['examine_reply'] && $check_examine())) {
            console.log(111)
        } else {
            $("#examine_reply").attr("disabled", "disabled");
        }

        //文本
        let booking_number = document.querySelector("#booking_number")
        booking_number.onkeyup = function (event) {
            form_data2.booking_number = event.target.value
        }
        //文本
        //文本
        let user_name = document.querySelector("#user_name")
        user_name.onkeyup = function (event) {
            form_data2.user_name = event.target.value
        }
        //文本
        //文本
        let identity_documents = document.querySelector("#identity_documents")
        identity_documents.onkeyup = function (event) {
            form_data2.identity_documents = event.target.value
        }
        //文本
        //文本
        let user_gender = document.querySelector("#user_gender")
        user_gender.onkeyup = function (event) {
            form_data2.user_gender = event.target.value
        }
        //文本
        //文本
        let user_phone_number = document.querySelector("#user_phone_number")
        user_phone_number.onkeyup = function (event) {
            form_data2.user_phone_number = event.target.value
        }
        //文本
        //文本
        let route_name = document.querySelector("#route_name")
        route_name.onkeyup = function (event) {
            form_data2.route_name = event.target.value
        }
        //文本
        //文本
        let route_number = document.querySelector("#route_number")
        route_number.onkeyup = function (event) {
            form_data2.route_number = event.target.value
        }
        //文本
        //文本
        let individual_expenses = document.querySelector("#individual_expenses")
        individual_expenses.onkeyup = function (event) {
            form_data2.individual_expenses = event.target.value
        }
        //文本
        //数字
        let number_of_bookings = document.querySelector("#number_of_bookings")
        number_of_bookings.onkeyup = function (event) {
            form_data2.number_of_bookings = Number(event.target.value)
        }
        //数字
        //文本
        let total_amount = document.querySelector("#total_amount")
        total_amount.onkeyup = function (event) {
            form_data2.total_amount = event.target.value
        }
        //文本
        // 计算
        var form_data3 = form_data2

        function zxxxx(form_data) {
            var o = {
                form: form_data
            }

            function k(o) {
                total_amount.value = parseFloat(this.form.individual_expenses) * parseFloat(this.form.number_of_bookings)
            }

            k.call(o)
        }

        total_amount.onfocus = function (event) {
            zxxxx(form_data3);
        }
        //多文本
        let booking_remarks = document.querySelector("#booking_remarks")
        //多文本
        booking_number.value = form_data2.booking_number
        $("#booking_number").attr("disabled", "disabled");
        var data = sessionStorage.data || ''
        if (data !== '') {
            var data2 = JSON.parse(data)
            Object.keys(form_data2).forEach(key => {
                Object.keys(data2).forEach(dbKey => {
                    if (key === dbKey) {
                        if (key !== 'examine_state' && key !== 'examine_reply') {
                            $('#' + key).val(data2[key])
                            form_data2[key] = data2[key]
                            $('#' + key).attr('disabled', 'disabled')
                            for (let key in form_data2) {
                                if (key == 'booking_account') {
                                    let alls = document.querySelector('#booking_account').querySelectorAll('option')
                                    let test = form_data2[key]
                                    for (let i = 0; i < alls.length; i++) {
                                        layui.form.render("select");
                                        if (alls[i].value == test) {
                                            alls[i].selected = true
                                            form_data2.booking_account = alls[i].value
                                            layui.form.render("select");
                                        }
                                    }
                                }
                            }


                        }
                    }
                })
            })
            sessionStorage.removeItem("data");
        }

        async function axios_get_4() {
            if (user_group != '管理员') {
                const {data: rese} = await axios.get(BaseUrl + '/api/user/get_list?user_group=' + user_group)
                let data = rese.result.list

                const {data: ress} = await axios.get(BaseUrl + '/api/user_group/get_obj?name=' + user_group)
                const {data: res} = await axios.get(BaseUrl + '/api/' + ress.result.obj.source_table + '/get_obj?user_id=' + use_id)
                Object.keys(form_data2).forEach(key => {
                    Object.keys(res.result.obj).forEach(dbKey => {
                        if (key === dbKey) {
                            if (key !== 'examine_state' && key !== 'examine_reply') {
                                $('#' + key).val(res.result.obj[key])
                                form_data2[key] = res.result.obj[key]
                                $('#' + key).attr('disabled', 'disabled')
                            }
                        }
                    })
                })

                for (let key in res.result.obj) {
                    if (key == 'user_id') {
                        let alls = document.querySelector('#booking_account').querySelectorAll('option')
                        let test = res.result.obj.user_id
                        for (let i = 0; i < alls.length; i++) {
                            if (alls[i].value == test) {
                                alls[i].selected = true
                                $('#booking_account').attr('disabled', 'disabled')
                                form_data2.booking_account = alls[i].value
                                layui.form.render("select");
                            }
                        }
                    }
                }
            }
        }

        axios_get_4()


        if (booking_records_id !== '') {
            async function axios_get_3() {
                const {data: rese} = await axios.get(BaseUrl + '/api/booking_records/get_obj', {
                    params: {
                        booking_records_id: booking_records_id
                    }, headers: {
                        'x-auth-token': token
                    }
                })

                let data = rese.result.obj
                Object.keys(form_data2).forEach((key) => {
                    form_data2[key] = data[key];
                    $("#" + key).val(form_data2[key])
                });


                for (let key in data) {
                    if (key == 'booking_account') {
                        let alls = document.querySelector('#booking_account').querySelectorAll('option')
                        let test = data[key]
                        for (let i = 0; i < alls.length; i++) {
                            layui.form.render("select");
                            if (alls[i].value == test) {
                                alls[i].selected = true
                                form_data2.booking_account = alls[i].value
                                layui.form.render("select");
                            }
                        }
                    }
                }


                for (let key in data) {
                    if (key == 'examine_state') {
                        let alls = document.querySelector('#examine_state').querySelectorAll('option')
                        let test = data[key]
                        for (let i = 0; i < alls.length; i++) {
                            if (alls[i].innerHTML == test) {
                                alls[i].selected = true
                                layui.form.render("select");
                            }
                        }
                    }
                }
                if (user_group === '管理员') {
                    $("#booking_account_box").show()
                } else {
                    if ($check_field('set', 'booking_account') || $check_field('get', 'booking_account')) {
                        $("#booking_account_box").show()
                    } else {
                        $("#booking_account_box").hide()
                    }
                }
                if (user_group === '管理员') {
                    $("#booking_number_box").show()
                } else {
                    if ($check_field('set', 'booking_number') || $check_field('get', 'booking_number')) {
                        $("#booking_number_box").show()
                    } else {
                        $("#booking_number_box").hide()
                    }
                }
                if (user_group === '管理员') {
                    $("#user_name_box").show()
                } else {
                    if ($check_field('set', 'user_name') || $check_field('get', 'user_name')) {
                        $("#user_name_box").show()
                    } else {
                        $("#user_name_box").hide()
                    }
                }
                if (user_group === '管理员') {
                    $("#identity_documents_box").show()
                } else {
                    if ($check_field('set', 'identity_documents') || $check_field('get', 'identity_documents')) {
                        $("#identity_documents_box").show()
                    } else {
                        $("#identity_documents_box").hide()
                    }
                }
                if (user_group === '管理员') {
                    $("#user_gender_box").show()
                } else {
                    if ($check_field('set', 'user_gender') || $check_field('get', 'user_gender')) {
                        $("#user_gender_box").show()
                    } else {
                        $("#user_gender_box").hide()
                    }
                }
                if (user_group === '管理员') {
                    $("#user_phone_number_box").show()
                } else {
                    if ($check_field('set', 'user_phone_number') || $check_field('get', 'user_phone_number')) {
                        $("#user_phone_number_box").show()
                    } else {
                        $("#user_phone_number_box").hide()
                    }
                }
                if (user_group === '管理员') {
                    $("#route_name_box").show()
                } else {
                    if ($check_field('set', 'route_name') || $check_field('get', 'route_name')) {
                        $("#route_name_box").show()
                    } else {
                        $("#route_name_box").hide()
                    }
                }
                if (user_group === '管理员') {
                    $("#route_number_box").show()
                } else {
                    if ($check_field('set', 'route_number') || $check_field('get', 'route_number')) {
                        $("#route_number_box").show()
                    } else {
                        $("#route_number_box").hide()
                    }
                }
                if (user_group === '管理员') {
                    $("#individual_expenses_box").show()
                } else {
                    if ($check_field('set', 'individual_expenses') || $check_field('get', 'individual_expenses')) {
                        $("#individual_expenses_box").show()
                    } else {
                        $("#individual_expenses_box").hide()
                    }
                }
                if (user_group === '管理员') {
                    $("#number_of_bookings_box").show()
                } else {
                    if ($check_field('set', 'number_of_bookings') || $check_field('get', 'number_of_bookings')) {
                        $("#number_of_bookings_box").show()
                    } else {
                        $("#number_of_bookings_box").hide()
                    }
                }
                if (user_group === '管理员') {
                    $("#total_amount_box").show()
                } else {
                    if ($check_field('set', 'total_amount') || $check_field('get', 'total_amount')) {
                        $("#total_amount_box").show()
                    } else {
                        $("#total_amount_box").hide()
                    }
                }
                if (user_group === '管理员') {
                    $("#booking_time_box").show()
                } else {
                    if ($check_field('set', 'booking_time') || $check_field('get', 'booking_time')) {
                        $("#booking_time_box").show()
                    } else {
                        $("#booking_time_box").hide()
                    }
                }
                if (user_group === '管理员') {
                    $("#booking_remarks_box").show()
                } else {
                    if ($check_field('set', 'booking_remarks') || $check_field('get', 'booking_remarks')) {
                        $("#booking_remarks_box").show()
                    } else {
                        $("#booking_remarks_box").hide()
                    }
                }

                // Array.prototype.slice.call(document.getElementsByTagName('input')).map(i => i.disabled = true)
                // Array.prototype.slice.call(document.getElementsByTagName('select')).map(i => i.disabled = true)
                // Array.prototype.slice.call(document.getElementsByTagName('textarea')).map(i => i.disabled = true)


                if (user_group === '管理员' || (form_data2['booking_records_id'] && $check_field('set', 'booking_account')) || (!form_data2['booking_records_id'] && $check_field('add', 'booking_account'))) {
                } else {
                    $("#booking_account").attr("disabled", true);
                    $("#booking_account > input[name='file']").attr('disabled', true);
                }
                //文本
                booking_number.value = form_data2.booking_number
                //文本


                if (user_group === '管理员' || (form_data2['booking_records_id'] && $check_field('set', 'booking_number')) || (!form_data2['booking_records_id'] && $check_field('add', 'booking_number'))) {
                } else {
                    $("#booking_number").attr("disabled", true);
                    $("#booking_number > input[name='file']").attr('disabled', true);
                }
                //文本
                user_name.value = form_data2.user_name
                //文本


                if (user_group === '管理员' || (form_data2['booking_records_id'] && $check_field('set', 'user_name')) || (!form_data2['booking_records_id'] && $check_field('add', 'user_name'))) {
                } else {
                    $("#user_name").attr("disabled", true);
                    $("#user_name > input[name='file']").attr('disabled', true);
                }
                //文本
                identity_documents.value = form_data2.identity_documents
                //文本


                if (user_group === '管理员' || (form_data2['booking_records_id'] && $check_field('set', 'identity_documents')) || (!form_data2['booking_records_id'] && $check_field('add', 'identity_documents'))) {
                } else {
                    $("#identity_documents").attr("disabled", true);
                    $("#identity_documents > input[name='file']").attr('disabled', true);
                }
                //文本
                user_gender.value = form_data2.user_gender
                //文本


                if (user_group === '管理员' || (form_data2['booking_records_id'] && $check_field('set', 'user_gender')) || (!form_data2['booking_records_id'] && $check_field('add', 'user_gender'))) {
                } else {
                    $("#user_gender").attr("disabled", true);
                    $("#user_gender > input[name='file']").attr('disabled', true);
                }
                //文本
                user_phone_number.value = form_data2.user_phone_number
                //文本


                if (user_group === '管理员' || (form_data2['booking_records_id'] && $check_field('set', 'user_phone_number')) || (!form_data2['booking_records_id'] && $check_field('add', 'user_phone_number'))) {
                } else {
                    $("#user_phone_number").attr("disabled", true);
                    $("#user_phone_number > input[name='file']").attr('disabled', true);
                }
                //文本
                route_name.value = form_data2.route_name
                //文本


                if (user_group === '管理员' || (form_data2['booking_records_id'] && $check_field('set', 'route_name')) || (!form_data2['booking_records_id'] && $check_field('add', 'route_name'))) {
                } else {
                    $("#route_name").attr("disabled", true);
                    $("#route_name > input[name='file']").attr('disabled', true);
                }
                //文本
                route_number.value = form_data2.route_number
                //文本


                if (user_group === '管理员' || (form_data2['booking_records_id'] && $check_field('set', 'route_number')) || (!form_data2['booking_records_id'] && $check_field('add', 'route_number'))) {
                } else {
                    $("#route_number").attr("disabled", true);
                    $("#route_number > input[name='file']").attr('disabled', true);
                }
                //文本
                individual_expenses.value = form_data2.individual_expenses
                //文本


                if (user_group === '管理员' || (form_data2['booking_records_id'] && $check_field('set', 'individual_expenses')) || (!form_data2['booking_records_id'] && $check_field('add', 'individual_expenses'))) {
                } else {
                    $("#individual_expenses").attr("disabled", true);
                    $("#individual_expenses > input[name='file']").attr('disabled', true);
                }
                //数字
                number_of_bookings.value = form_data2.number_of_bookings
                //数字


                if (user_group === '管理员' || (form_data2['booking_records_id'] && $check_field('set', 'number_of_bookings')) || (!form_data2['booking_records_id'] && $check_field('add', 'number_of_bookings'))) {
                } else {
                    $("#number_of_bookings").attr("disabled", true);
                    $("#number_of_bookings > input[name='file']").attr('disabled', true);
                }
                //文本
                total_amount.value = form_data2.total_amount
                //文本


                if (user_group === '管理员' || (form_data2['booking_records_id'] && $check_field('set', 'total_amount')) || (!form_data2['booking_records_id'] && $check_field('add', 'total_amount'))) {
                } else {
                    $("#total_amount").attr("disabled", true);
                    $("#total_amount > input[name='file']").attr('disabled', true);
                }


                if (user_group === '管理员' || (form_data2['booking_records_id'] && $check_field('set', 'booking_time')) || (!form_data2['booking_records_id'] && $check_field('add', 'booking_time'))) {
                } else {
                    $("#booking_time").attr("disabled", true);
                    $("#booking_time > input[name='file']").attr('disabled', true);
                }
                //多文本
                booking_remarks.value = form_data2.booking_remarks
                //多文本


                if (user_group === '管理员' || (form_data2['booking_records_id'] && $check_field('set', 'booking_remarks')) || (!form_data2['booking_records_id'] && $check_field('add', 'booking_remarks'))) {
                } else {
                    $("#booking_remarks").attr("disabled", true);
                    $("#booking_remarks > input[name='file']").attr('disabled', true);
                }
                booking_time.value = layui.util.toDateString(form_data2.booking_time, "yyyy-MM-dd HH:mm:ss")
                layui.form.render("select");
            }

            axios_get_3()
        }


        submit.onclick = async function () {
            try {
                //文本
                form_data2.booking_number = booking_number.value
                //文本
                //文本
                form_data2.user_name = user_name.value
                //文本
                //文本
                form_data2.identity_documents = identity_documents.value
                //文本
                //文本
                form_data2.user_gender = user_gender.value
                //文本
                //文本
                form_data2.user_phone_number = user_phone_number.value
                //文本
                //文本
                form_data2.route_name = route_name.value
                //文本
                //文本
                form_data2.route_number = route_number.value
                //文本
                //文本
                form_data2.individual_expenses = individual_expenses.value
                //文本
                //数字
                form_data2.number_of_bookings = Number(number_of_bookings.value)
                //数字
                //文本
                form_data2.total_amount = total_amount.value
                //文本
                form_data2.booking_time = layui.util.toDateString(form_data2.booking_time, "yyyy-MM-dd HH:mm:ss")
                //多文本
                form_data2.booking_remarks = booking_remarks.value
                //多文本
            } catch (err) {
                console.log(err)
            }
            if (!form_data2.booking_time) {
                layer.msg('预订时间不能为空');
                return;
            }
            let examine_reply = document.querySelector("#examine_reply")
            form_data2.examine_reply = examine_reply.value


            let customize_field = []
            customize_field.push({"field_name": "预订账号", "field_value": form_data2.booking_account});
            customize_field.push({"field_name": "预订编号", "field_value": form_data2.booking_number});
            customize_field.push({"field_name": "用户姓名", "field_value": form_data2.user_name});
            customize_field.push({"field_name": "身份证件", "field_value": form_data2.identity_documents});
            customize_field.push({"field_name": "用户性别", "field_value": form_data2.user_gender});
            customize_field.push({"field_name": "用户电话", "field_value": form_data2.user_phone_number});
            customize_field.push({"field_name": "路线名称", "field_value": form_data2.route_name});
            customize_field.push({"field_name": "路线编号", "field_value": form_data2.route_number});
            customize_field.push({"field_name": "单人费用", "field_value": form_data2.individual_expenses});
            customize_field.push({"field_name": "预订人数", "field_value": form_data2.number_of_bookings});
            customize_field.push({"field_name": "总计金额", "field_value": form_data2.total_amount});
            customize_field.push({
                "field_name": "预订时间",
                "field_value": form_data2.booking_time,
                "type": "datetime"
            });
            customize_field.push({"field_name": "预订备注", "field_value": form_data2.booking_remarks});


            if (booking_records_id == '') {
                console.log("新增/Add")
                const {data: res} = await axios.post(BaseUrl + '/api/booking_records/add?',
                    form_data2, {
                        headers: {
                            'x-auth-token': token,
                            'Content-Type': 'application/json'
                        }
                    })
                if (res.result == 1) {
                    layer.msg('确认完毕');
                    setTimeout(function () {
                        colseLayer()
                    }, 1000)
                } else {
                    layer.msg(res.error.message);
                }
            } else {
                console.log("详情/Details")

                const {data: res} = await axios.post(BaseUrl + '/api/booking_records/set?booking_records_id=' + booking_records_id,
                    form_data2, {
                        headers: {
                            'x-auth-token': token,
                            'Content-Type': 'application/json'
                        }
                    })
                if (res.result == 1) {
                    layer.msg('确认完毕');
                    setTimeout(function () {
                        colseLayer()
                    }, 1000)
                } else {
                    layer.msg(res.error.message);
                }
            }
        }

    })
    ;
</script>
<style>
    .layui-unselect.layui-form-select {
        width: auto;
    }
</style>
</html>
